struct Solution {}

impl Solution {
  pub fn count_quadruplets(nums: Vec<i32>) -> i32 {
    fn add (l: usize, n: usize, mut val: i32, nums: &Vec<i32>) -> i32  {
      if l == 3 {
        (n+1..nums.len()).map(|i| if nums[i] == val { 1 } else { 0 }).sum()
      } else {
        (n..nums.len()).map(|i| {
          add(l+1, i + 1, val + nums[i], nums)
        }).sum()    
        }
      }
    add(0, 0 , 0, &nums)   
  }
}